using System;
using System.ComponentModel;
using System.Windows.Forms;
using InfoExpress.HIV.WinApp.Utils;
using InfoExpress.WinApp.Utils;
using InfoExpress.HIV.Domains;
using InfoExpress.HIV.WinApp.Business;

namespace InfoExpress.HIV.WinApp.Forms
{
  public partial class FrmDsChuaDuyet : DevExpress.XtraEditors.XtraForm
  {
    private TList<BenhNhanDangKy> _benhNhanDangKyList;

    public FrmDsChuaDuyet()
    {
      InitializeComponent();
    }

    #region Event Handlers

    private void FrmDsDaDuyet_Load(object sender, EventArgs e)
    {
      LoadData();
    }

    #region Data Loading

    private void bwDataLoading_DoWork(object sender, DoWorkEventArgs e)
    {
      try
      {
        _benhNhanDangKyList = GlobalCache.BenhNhanDangKyService.DsBenhNhanTheoTrangThai
          (GlobalCache.Permission.UnitCode, (int)BenhNhanUtils.TrangThai.ChuaDuyet, null, null);
      }
      catch (Exception ex)
      {
        _benhNhanDangKyList = null;
        Logger.LogCritical("FrmDsChuaDuyet::bwDataLoading_DoWork", ex, "General", null);
      }
    }

    private void bwDataLoading_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
      Cursor = Cursors.Default;
      MainFormUtils.StopProgress();

      if (_benhNhanDangKyList != null)
      {
        gcDsBenhNhan.DataSource = _benhNhanDangKyList;
        lblCount.Text = _benhNhanDangKyList.Count.ToString();
        MainFormUtils.SetLoadedStatus();
      }
      else
      {
        lblCount.Text = "0";
        MainFormUtils.SetLoadedFailedStatus();
        UIUtils.ShowCannotLoadDataMessage();
      }
      
    }

    #endregion DataLoading BackgroundWorker 

    #endregion

    #region Helper Methods

    private void LoadData()
    {
      Cursor = Cursors.WaitCursor;
      MainFormUtils.StartProgress();
      MainFormUtils.SetLoadingStatus();
      bwDataLoading.RunWorkerAsync();
    }

    #endregion
  }
}